package eerbaar.v2.pattern.client.internal.request;

import eerbaar.v2.gamebuilder.client.request.IRequestProcessor;
import eerbaar.v2.pattern.client.internal.teach.TeachingMediator;

public class RequestProcessor2 implements IRequestProcessor {

    private String program;
    private final TeachingMediator mediator;

    public RequestProcessor2(TeachingMediator mediator) {
        this.mediator = mediator;
    }

    @Override
    public boolean needsProcessing() {
        return (this.program != null);
    }

    @Override
    public void processInGameLoop() {

        if (this.program != null) {
            this.mediator.onNewProgram(this.program);
            this.program = null;
        } else {
            this.mediator.onNoProgram();
        }
    }

    @Override
    public void processInWorkerThread(String data) {
        this.program = data;
    }

}
